<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../../assets/libs/jquery/jquery-3.6.1.min.js"></script>
</head>

<body>
  <input type="text">
  <button id="focus">focus()</button>
  <button id="trigger">trigger('focus')</button>
  <button id="triggerHandler">triggerHandler('focus')</button>

  <script>
    $('input').focus(event => {
      console.log('focus')
    })

    $('#focus').click(() => {
      // 触发事件
      $('input').focus()
    })

    $('#trigger').click(() => {
      // 触发事件
      $('input').trigger('focus')
    })

    $('#triggerHandler').click(() => {
      // 触发事件，并阻止默认行为
      $('input').triggerHandler('focus')
    })
  </script>
</body>

</html>